package cn.csc.module.pay.controller.admin.jzborder;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.math.BigInteger;
import java.util.*;
import java.io.IOException;

import cn.csc.framework.common.pojo.PageResult;
import cn.csc.framework.common.pojo.CommonResult;
import static cn.csc.framework.common.pojo.CommonResult.success;

import cn.csc.framework.excel.core.util.ExcelUtils;

import cn.csc.framework.operatelog.core.annotations.OperateLog;
import static cn.csc.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.csc.module.pay.controller.admin.jzborder.vo.*;
import cn.csc.module.pay.dal.dataobject.jzborder.JzbOrderDO;
import cn.csc.module.pay.convert.jzborder.JzbOrderConvert;
import cn.csc.module.pay.service.jzborder.JzbOrderService;

@Api(tags = "管理后台 - 见证宝订单表(挂账)")
@RestController
@RequestMapping("/pay/jzb-order")
@Validated
public class JzbOrderController {

    @Resource
    private JzbOrderService jzbOrderService;


    @GetMapping("/get")
    @ApiOperation("获得见证宝订单表(挂账)")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('pay:jzb-order:query')")
    public CommonResult<JzbOrderRespVO> getJzbOrder(@RequestParam("id") BigInteger id) {
        JzbOrderDO jzbOrder = jzbOrderService.getJzbOrder(id);
        return success(JzbOrderConvert.INSTANCE.convert(jzbOrder));
    }

    @GetMapping("/list")
    @ApiOperation("获得见证宝订单表(挂账)列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('pay:jzb-order:query')")
    public CommonResult<List<JzbOrderRespVO>> getJzbOrderList(@RequestParam("ids") Collection<BigInteger> ids) {
        List<JzbOrderDO> list = jzbOrderService.getJzbOrderList(ids);
        return success(JzbOrderConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得见证宝订单表(挂账)分页")
    @PreAuthorize("@ss.hasPermission('pay:jzb-order:query')")
    public CommonResult<PageResult<JzbOrderRespVO>> getJzbOrderPage(@Valid JzbOrderPageReqVO pageVO) {
        PageResult<JzbOrderDO> pageResult = jzbOrderService.getJzbOrderPage(pageVO);
        return success(JzbOrderConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出见证宝订单表(挂账) Excel")
    @PreAuthorize("@ss.hasPermission('pay:jzb-order:export')")
    @OperateLog(type = EXPORT)
    public void exportJzbOrderExcel(@Valid JzbOrderExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<JzbOrderDO> list = jzbOrderService.getJzbOrderList(exportReqVO);
        // 导出 Excel
        List<JzbOrderExcelVO> datas = JzbOrderConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "见证宝订单表(挂账).xls", "数据", JzbOrderExcelVO.class, datas);
    }

}
